<?php

use yii\db\Migration;

/**
 * Handles the creation of table `{{%decree}}`.
 * Has foreign keys to the tables:
 *
 * - `{{%decree_type}}`
 */
class m221026_112839_create_decree_table extends Migration
{
    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
        $this->createTable('{{%decree}}', [
            'id' => $this->primaryKey(),
            'title' => $this->string(),
            'date_signture' => $this->date(),
            'file_name' => $this->string(),
            'comment' => $this->string(512),
            'id_type' => $this->integer()->notNull(),
        ]);

        // creates index for column `id_type`
        $this->createIndex(
            '{{%idx-decree-id_type}}',
            '{{%decree}}',
            'id_type'
        );

        // add foreign key for table `{{%decree_type}}`
        $this->addForeignKey(
            '{{%fk-decree-id_type}}',
            '{{%decree}}',
            'id_type',
            '{{%decree_type}}',
            'id',
            'CASCADE'
        );
    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        // drops foreign key for table `{{%decree_type}}`
        $this->dropForeignKey(
            '{{%fk-decree-id_type}}',
            '{{%decree}}'
        );

        // drops index for column `id_type`
        $this->dropIndex(
            '{{%idx-decree-id_type}}',
            '{{%decree}}'
        );

        $this->dropTable('{{%decree}}');
    }
}
